home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / ARB-ROM.C next >
C/C++ Source or Header  |  1993-05-18  |  3KB  |  78 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 05-14-93 (02:41)             Number: 42
  4. From: SEAN MUNSON                  Refer#: NONE
  5.   To: ALL                           Recvd: NO  
  6. Subj: blah                           Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. Here's a Program to Change from Arabic to Roman numerals and back.
  9. #include<stdio.h>;
  10. #include<string.h>;
  11.         /*
  12.         this Program is hereby donated to the public domain by the author,
  13.         Sean Munson. Enjoy it! no Promises or elsewise.
  14.         */
  15. char * arabictoroman(int x);
  16. int  *romantoarabic(char *r);
  17. main(){
  18.         char *romannum;
  19.         int arabicnum;
  20.         printf("\n enter a roman numeral here:");
  21.         gets(romannum);
  22.         printf(" %s = %d \n",arabicnum,romantoarabic(romannum));}
  23. char * arabictoroman(int x){
  24.         char tval[50]={"                                                 "};
  25.         int i=0;
  26.         while (x>1000){x-=1000; tval[i++]='m'; }
  27.         while (x>900) {x-=900;  tval[i++]='c'; tval[i++]='m';}
  28.         while (x>500) {x-=500;  tval[i++]='d'; }
  29.         while (x>400) {x-=400;  tval[i++]='c'; tval[i++]='d';}
  30.         while (x>100) {x-=100;  tval[i++]='c'; }
  31.         while (x>90)  {x-=90;   tval[i++]='x'; tval[i++]='c';}
  32.         while (x>50)  {x-=50;   tval[i++]='l'; }
  33.         while (x>40)  {x-=40;   tval[i++]='x'; tval[i++]='x';}
  34.         while (x>10)  {x-=10;   tval[i++]='x'; }
  35.         while (x>9)   {x-=9;    tval[i++]='i'; tval[i++]='x';}
  36.         while (x>5)   {x-=5;    tval[i++]='v'; }
  37.         while (x>4)   {x-=4;    tval[i++]='i'; tval[i++]='v';}
  38.         while (x>=1)   {x--;     tval[i++]='i'; }
  39.         tval[i++]=0;
  40.         return tval;
  41. }
  42. int romantoarabic(char *r){
  43.         int sum=0;
  44.         int i=0;
  45.         strlwr(r);
  46.         for (i=0;i<strlen(r);i++){
  47.          switch(r[i]){
  48.          case 'i': if (r[i+1]=='v'){sum+=4;i++;break;}
  49.                   else sum++;
  50.                   break;
  51.          case 'v': if (r[i+1]=='x'){sum+=9;i++;break;}
  52.                   else sum+=5;
  53.                   break;
  54.          case 'x': if (r[i+1]=='c'){sum+=90;i++;break;}
  55.                   else if (r[i+1]=='l'){sum+=40;i++;break;}
  56.                   else sum+=10;
  57.                   break;
  58.          case 'l' :sum+=50;
  59.                   break;
  60.          case 'c' :if (r[i+1]=='m'){sum+=900;i++;break;}
  61.                   else if (r[i+1]=='d'){sum+=400;i++;break;}
  62.                   else sum+=100;
  63.                   break;
  64.          case 'd' :sum+=500;
  65.                   break;
  66.          case 'm' :sum+=1000;
  67.                   break;
  68.          }
  69.         }
  70. return sum;
  71. }
  72.  
  73. --- Maximus/2 2.01wb
  74.  * Origin: The Excelsior (1:141/222)
  75. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  76. SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
  77. SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  78.